package pkg

import (
	"fmt"
	"github.com/smartwalle/alipay/v3"
	"zg2_zy/zy11_cart/cartRpc/appConfig"
)

func AliPay(amount, outTradeNo string) string {
	data := appConfig.ConfigData.AliPay
	var appId = data.AppId
	var privateKey = data.PrivateKey // 必须，上一步中使用 RSA签名验签工具 生成的私钥
	var client, err = alipay.New(appId, privateKey, false)
	if err != nil {
		fmt.Println(err)
		return ""
	}

	var p = alipay.TradeWapPay{}
	p.NotifyURL = "http://xxx"
	p.ReturnURL = "http://xxx"
	p.Subject = "给小羊买奔驰"
	p.OutTradeNo = outTradeNo //订单号
	p.TotalAmount = amount    //金额
	p.ProductCode = "QUICK_WAP_WAY"

	url, err := client.TradeWapPay(p)
	if err != nil {
		fmt.Println(err)
		return ""
	}

	var payUrl = url.String()
	fmt.Println(payUrl)
	return payUrl
}
